﻿// <copyright file="MatrixTransform3D.cs" company="Axelerate Solutions S.A.">
// Copyright (c) Axelerate Solutions S.A.  All rights reserved.
// </copyright>
namespace Axelerate.Silverlight3D.Media.Media3D
{
    using System;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Ink;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;

    /// <summary>
    /// File name: MatrixTransform3D.cs
    /// Company: Axelerate Solutions S.A.
    /// Created By: Daniel Rojas
    /// Created Date: 10/13/2008 9:11:00 h.
    /// Description: Creates a transformation specified by a Matrix3D, used to manipulate objects or coordinate systems in 3-D world space.
    ///   <Modifications>
    ///   </Modifications>
    /// </summary>
    public sealed class MatrixTransform3D : Transform3D
    {
        #region Fields
        
        /// <summary>
        /// Identifies the Matrix dependency property.
        /// </summary>
        public static readonly DependencyProperty MatrixProperty =
                    DependencyProperty.Register(
                          "Matrix",
                          typeof(Matrix3D),
                          typeof(MatrixTransform3D),
                          new PropertyMetadata(OnMatrixPropertyChanged));
        #endregion

        #region Properties
        
        /// <summary>
        /// Gets or sets a Matrix3D that specifies one or more 3-D transformations.
        /// </summary>
        public Matrix3D Matrix
        {
            get
            {

                return (Matrix3D)this.GetValue(MatrixProperty);
            }
            set
            {
                this.SetValue(MatrixProperty, value);
            }
        }

        /// <summary>
        /// Gets a value that indicates whether the transform is affine.
        /// </summary>
        public override bool IsAffine
        {
            get
            {
                return Matrix.IsAffine;
            }
        }

        /// <summary>
        /// Gets a matrix representation of the 3-D transformation.  This is a dependency property.
        /// </summary>
        public override Matrix3D Value
        {
            get
            {
                return Matrix;
            }
        }

        
        #endregion

        #region Constructors
        
        /// <summary>
        /// Initializes a new instance of the MatrixTransform3D class.
        /// </summary>
        public MatrixTransform3D()
            : base()
        {
            Matrix = Matrix3D.Identity;
        }

        /// <summary>
        /// Initializes a new instance of the MatrixTransform3D class using the specified Matrix3D.
        /// </summary>
        /// <param name="matrix">Matrix3D that specifies the transform.</param>
        public MatrixTransform3D(Matrix3D matrix)
            : base()
        {
            Matrix = matrix;
        }
        #endregion

        #region Methods
        
        /// <summary>
        /// Raise the Matrix changed event
        /// </summary>
        /// <param name="d">DependencyObject owner of the property</param>
        /// <param name="e">DependencyPropertyChangedEventArgs with the necesary information</param>
        private static void OnMatrixPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            ((MatrixTransform3D)d).NotifyPropertyChanged("Matrix");
        }

        #endregion
    }
}
